/*
 * Copyright (c) 2018. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.xlkj.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootBroadcastReceiver extends BroadcastReceiver {

    private static final String TAG="BootBroadcastReceiver";

    //系统启动
    static final String BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
    //充电状态-连接充电线
    static final String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
    //充电状态-拔出充电线
    static final String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION_POWER_DISCONNECTED";
    @Override
    public void onReceive(final Context context, Intent intent) {
        String action = intent.getAction();
        if(action.equals(ACTION_POWER_CONNECTED)){
            Log.i(TAG, "连接充电线!!!");
            PowerUtil.unlockDevice(context);
        }else if(action.equals(ACTION_POWER_DISCONNECTED)){
            Log.i(TAG, "拔出充电线!!!");
            PowerUtil.lockDevice(context);
        }else if(action.equals(BOOT_COMPLETED)){
            Log.i(TAG, "系统启动!!!");
            PowerUtil.restartApp(context);
        }else{
            Log.d(TAG, action);
        }
    }
}
